package main

import (
	"context"
	"go.mongodb.org/mongo-driver/bson"
	"go.mongodb.org/mongo-driver/mongo"
	"go.mongodb.org/mongo-driver/mongo/options"
	"my_go_open/utils"
)

func main() {
	client, err := utils.MongoClient(`mongodb://root:abc123@localhost:27017`)
	if err != nil {
		utils.VarDump(err.Error())
		return
	}
	collection := client.Database("learn").Collection("test_1")
	unique := true
	indexModel := mongo.IndexModel{
		Keys: bson.D{
			{"str1", 1},
			{"str2", 1},
		},
		Options: &options.IndexOptions{
			Unique: &unique,
		},
	}
	ret, err := collection.Indexes().CreateOne(context.TODO(), indexModel)
	utils.VarDump(ret, err)
}
